import '@umijs/max';
import React, {useEffect, useRef} from 'react';
import {ProTable, ProColumns, ProFormInstance} from "@ant-design/pro-components";
import {Modal} from "antd";


export type Props = {
  values: API.Api;
  columns: ProColumns<API.FileRecordUpdateRequest>[];
  onCancel: () => void;
  onSubmit: (values: API.Api) => Promise<void>;
  visible: boolean;
};
const UpdateModal: React.FC<Props> = (props) => {
  const {values, visible, columns, onCancel, onSubmit} = props;
  const formRef = useRef<ProFormInstance>();
  useEffect(() => {
    if (formRef) {
      formRef.current?.setFieldsValue(values);
    }
  }, [values])
  return <Modal visible={visible} footer={null} onCancel={() => onCancel?.()}>
    <ProTable type='form' columns={columns} form={{initialValues: values}} onSubmit={async (value) => {
      onSubmit?.(value);
    }}/>
  </Modal>
};
export default UpdateModal;
